// index.js
import { userFind,download } from "../../public/api/person.js"
import { signInAgain } from "../../public/api/login.js"
const app = getApp();
Page({
  data: {
    translations: {},
    bannerList: [
      'http://121.37.136.48:8099/banner2.jpg',
      'http://121.37.136.48:8099/banner3.jpg',
      'http://121.37.136.48:8099/banner4.jpg',
      'http://121.37.136.48:8099/banner5.jpg',
      'http://121.37.136.48:8099/banner6.jpg',
      'http://121.37.136.48:8099/banner8.jpg',
    ],
    currentTab: 0,
    videoUrl: 'http://121.37.136.48:8099/video.mp4'
  },

  //查询人员信息
  signAgain() {
    signInAgain().then(res => {
      if(res.data.code === 1) {
        wx.setStorageSync('userInfo', res.data.data)
        let { userName,photoId } = res.data.data.extra
        app.globalData.userInfo = {
          name: userName,
          photoId
        }
        if(photoId) this.getPhoto(photoId)
      } else {
        wx.reLaunch({
          url: '/packageLogin/pages/login/login'
        })
      }
    })
  },

  // 查询照片
  getPhoto(photoId) {
    let data = {}
    data.id = photoId
    download(data).then(res => {
      if(res.statusCode === 200) {
        app.globalData.userInfo.faceData = res.data
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },


  switchTab(e) {
    let currentTab = e.currentTarget.dataset.index
    this.setData({currentTab})
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const translations = app.globalData.translations;
    let language = wx.getStorageSync('language')
    this.setData({
      language,
      translations
    });
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0,
        list: translations.list
      });
    }
    if(wx.getStorageSync('userInfo').token) {
      this.signAgain()
    } else {
      wx.reLaunch({
        url: '/packageLogin/pages/login/login'
      })
    }
  },
})